﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using control.Biz;

public partial class usercontrol_login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["account"] != null)
        {
            Panel1.Visible = false;
            Panel2.Visible = true;
            BizKhachHang _user = (BizKhachHang)Session["account"];
            Label4.Text = _user.TenKH;
        }
        else
        {
            Panel2.Visible = false;
            Panel1.Visible = true;
        }
        btDangXuat.Click += new EventHandler(btDangXuat_Click);
    }

    void btDangXuat_Click(object sender, EventArgs e)
    {
        Session["account"] = null ;
        Panel2.Visible = false;
        Panel1.Visible = true;
        string url = Request.Url.ToString();
        Response.Redirect(url);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string _username = TextBox1.Text;
        string _password = TextBox2.Text;
        BizKhachHang _user = BizKhachHang.DangNhap(_username, _password);
        if (_user != null)
        {
            Session["account"] = _user;
            Panel1.Visible = false;
            Panel2.Visible = true;
            Label4.Text = _user.TenKH;
            lberro.Text = "";
        }
        else
        {
            lberro.Text = "Đăng Nhập Thất Bại";
        }
            
    }
}
